/**
  data-receiver.h - Created by Timothy Morey on 3/14/2012.

  This file defines an interface by which a program may receive data over a
  dedicated one-way socket.
*/

#ifndef __DATA_RECEIVER_H
#define __DATA_RECEIVER_H

/**
  Indicates the various states that a DataReceiver may occupy.
*/
typedef enum ReceiverStatus
{
  Idle,      /* The DataReciever has been created, but is not running. */
  Receiving  /* The DataReceiver is filling the FrameBuffer. */
} ReceiverStatus;

/**
  The DataReceiver structure represents a dedicated one-way socket connection
  through which this process can receive data from another process.
*/
typedef struct
{
  char ServerName[128];
  char ServerPort[8];
  ReceiverStatus Status;
  char* FrameBuffer;
  size_t FrameBufferSize;
  int FrameId;
} DataReceiver;

/**
  Initializes a new DataReceiver structure that represents a connection to the
  specified server.

  @param server The fully-qualified domain name of the server.
  @param port The port through which we will connect on the server.

  @return A new DataReceiver instance.  When no longer needed, it is the
  caller's responsibility to dispose of the instance by calling the
  DestroyDataReceiver function.
*/
DataReceiver* CreateDataReceiver(const char* server, const char* port);

/**
  Destroys a DataReceiver previously created with InitDataReceiver.

  @param dr The instance that will destroyed.
*/
void DestroyDataReceiver(DataReceiver* dr);

int LockFrameBuffer(DataReceiver* dr);

void ReleaseFrameBufferLock(DataReceiver* dr);

int StartDataReceiver(DataReceiver* dr);

void StopDataReceiver(DataReceiver* dr);

#endif
